
#include "ToolBar.h"

#include <QLabel>
#include <QAction>


ToolBar::ToolBar(const QString& title, QWidget* parent /* = 0 */) : QToolBar(title, parent)
{
	QAction *action = new QAction(this);
	QIcon *theIcon = new QIcon(QPixmap(":/res/bw_openfile.png"));
	action->setToolTip(QString("Open File"));
	action->setIcon(*theIcon);
	connect(action, SIGNAL(triggered()), SIGNAL(emitOpenFile()));
	addAction(action);

	action = new QAction(this);
	action->setToolTip(QString("Open Dir"));
	action->setIcon(QIcon(QPixmap(":/res/bw_opendir.png")));
	action->setIconVisibleInMenu(true);
	connect(action, SIGNAL(triggered()), SIGNAL(emitOpenDir()));
	addAction(action);

	action = new QAction(this);
	action->setToolTip(QString("Save"));
	action->setIcon(QIcon(QPixmap(":/res/bw_save.png")));
	connect(action, SIGNAL(triggered()), SIGNAL(emitSaveSource()));
	addAction(action);

	action = new QAction(this);
	action->setToolTip(QString("Delete"));
	action->setIcon(QIcon(QPixmap(":/res/bw_delete.png")));
	connect(action, SIGNAL(triggered()), SIGNAL(emitRemoveSource()));
	addAction(action);

	addSeparator();

	action = new QAction(this);
	action->setToolTip(QString("Create Surface"));
	action->setIcon(QIcon(QPixmap(":/res/bw_createsurface.png")));
	connect(action, SIGNAL(triggered()), SIGNAL(emitCreateSurfaceSource()));
	addAction(action);

	action = new QAction(this);	
	action->setCheckable(true);
	action->setToolTip(QString("Link Cameras"));
	action->setIcon(QIcon(QPixmap(":/res/bw_link.png")));
	connect(action, SIGNAL(toggled(bool)), SIGNAL(emitLinkCameras(bool)));
	addAction(action);

	addSeparator();

	QLabel *label = new QLabel(this);
	label->setText("Seeds:");
	addWidget(label);

 	m_comboSeeds = new QComboBox(this);
	m_comboSeeds->setInsertPolicy(QComboBox::InsertAtTop);
	m_comboSeeds->setMinimumSize(QSize(80, 0));
	connect(m_comboSeeds, SIGNAL(currentIndexChanged(QString)), SLOT(slotSeedSelected(QString)));
	addWidget(m_comboSeeds);


	action = new QAction(this);	
	action->setToolTip(QString("Add Seed"));
	action->setIcon(QIcon(QPixmap(":/res/bw_add.png")));
	connect(action, SIGNAL(triggered()), SIGNAL(emitPickSeed()));
	addAction(action);

	action = new QAction(this);	
	action->setToolTip(QString("Remove current seed"));
	action->setIcon(QIcon(QPixmap(":/res/bw_minus.png")));
	connect(action, SIGNAL(triggered()), SLOT(slotRemoveCurrentSeed()));
	addAction(action);

	m_showColorDialog = new QCheckBox;
	m_showColorDialog->setChecked(false);
	m_showColorDialog->setText("Show Color Dialog");

	addWidget(m_showColorDialog);

	addSeparator();
}


void ToolBar::slotUpdateSeeds(const QStringList& seeds)
{
	m_comboSeeds->clear();

	if ( seeds.count())
	{
		m_comboSeeds->addItems(seeds);
	}
}


void ToolBar::slotRemoveCurrentSeed()
{
	QString str = m_comboSeeds->currentText();

	if ( !str.isEmpty())
		emit emitRemoveSeed(str);
}

QString ToolBar::currentSeed()
{
	return m_comboSeeds->currentText();
}

void ToolBar::slotSeedSelected( QString str)
{
	emit emitSeedSelected(str);
}

bool ToolBar::getColorDialogStatus()
{
	return m_showColorDialog->isChecked();
}
